﻿/*
* Activity Tracking Log v0.1.1 - http://activitytrackinglog.codeplex.com
* Activity Tracking Log for ASP.Net & ASP.Net MVC
* Copyright (c) 2011 Vadim Burac
* Licensed under the Microsoft Public License (Ms-PL)
* http://activitytrackinglog.codeplex.com/license
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ActivityTrackingLog.Utils;
using ActivityTrackingLog.Web.Utils;

namespace ActivityTrackingLog.Web.Helpers.ViewEngines
{
    internal class ListControlRenderer<T> : BaseRenderer<T> where T : class
    {
        public ListControlRenderer() : base(HtmlHelper.ViewTypeEnum.Control, HtmlHelper.ReportTypeEnum.List) { }

        public ListControlRenderer(HtmlHelper.ViewTypeEnum viewType) : base(viewType, HtmlHelper.ReportTypeEnum.List) { }

        protected override KeyValuePair<string, Enums.SortDirectionEnum> GetDefaultColumnSort()
        {
            return new KeyValuePair<string, Enums.SortDirectionEnum>("Sequence", Enums.SortDirectionEnum.Descending);
        }

        public override string GetContentTemplate()
        {
            return ResourceHelper.GetListControlHtml();
        }

        public override string GetStylesBody()
        {
            string layoutStyles = ResourceHelper.GetListLayoutStyles();
            return base.EmbedThemeStyles ? layoutStyles + ResourceHelper.GetListThemeStyles() : layoutStyles;
        }

        public override string GetContentBody(out int totalRecords, out string navigationControls)
        {
            string bodyContent = "<table class=\"content\"><thead>{0}</thead><tbody>{1}</tbody></table>";

            // build header
            string thead = BuildTableHeader();
            thead += "<th class=\"last_column\"></th>";

            // build body
            var plainList = _logRepository.GetFlatList<T>(base.UserId, base.PageIndex, base.PageSize, base.Columns, out totalRecords);
            string tbody = BuildDataTableBody(plainList);

            // build navigation controls
            navigationControls = GetNavigationControlsLayout(totalRecords: totalRecords, pageSize: base.PageSize, currentPageIndex: base.PageIndex);

            return string.Format(bodyContent, thead, tbody);
        }
    }
}
